﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Class_Entity;
using BussinessObject;

public partial class WebApplication_Encapsulation : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            loadGrid();

        }
    }

    //load products to datalist
    private void loadGrid()
    {
        Encapsulation en = new Encapsulation();
        BOProducts pro = new BOProducts();

        DataList1.DataSource = pro.Load_Encapsulation(en);
        DataList1.DataBind();
    }



    // search products by name
    protected void btSearch_Click(object sender, EventArgs e)
    {
        Encapsulation en = new Encapsulation();
        BOProducts pro = new BOProducts();

        en.Model = txtSearch.Text;

        DataList1.DataSource = pro.Search_Encapsulation(en);
        DataList1.DataBind();
    }


    // direct to choosen products detail page
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "detail")
        {
            DataList1.SelectedIndex = e.Item.ItemIndex;
            
            Session["ID"] = ((LinkButton)DataList1.SelectedItem.FindControl("LinkButton1")).Text;
            Response.Redirect("EncapsulationDetail.aspx");
        }
    }
}